package org.example.demo3.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 商品分类类型枚举类
 * 作者:xuSen
 * 日期2025/3/13 22:49
 */
@Getter
@AllArgsConstructor
public enum ProductTypeEnum {
    DIGITAL_ELECTRONICS(1, "数码电子"),
    CLOTHING_ACCESSORIES(2, "服装配饰"),
    BOOKS_SUPPLIES(3, "图书文具"),
    DAILY_ESSENTIALS(4, "生活用品"),
    SPORTS_OUTDOORS(5, "运动户外"),
    VEHICLES(6, "交通工具"),
    TICKET_SERVICE(7, "票券服务"),
    OTHER(8, "其他");
    @EnumValue
    private final Integer code;
    private final String categoryName;
    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static ProductTypeEnum fromCode(int code) {
        return Arrays.stream(values())
                .filter(e -> e.getCode() == code)
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("无效分类码: " + code));
    }
    @JsonValue
    public Integer getCode() {
        return code;
    }
}
